package cn.com.infcn.monitor.util;

/*
 * @Title: JNIopenssl.java @Package cn.sccl.common.util @Description:
 * TODO(调用本地C++加密方法) @author YangDong @date 2011-11-24 下午02:57:17
 * 
 * @version V1.0
 */
import java.lang.reflect.Field;
import java.util.Properties;

public class LibraryPath {

	public static void main(String[] args) {
		Properties properties = System.getProperties();

		for (Object key : properties.keySet()) {
			System.out.println(key + "\t" + System.getProperty(key.toString()));
			;
		}
	}

	public static void addDir(String s) {
		try {
			Field field = ClassLoader.class.getDeclaredField("usr_paths");
			field.setAccessible(true);
			String[] paths = (String[]) field.get(null);
			for (int i = 0; i < paths.length; i++) {
				if (s.equals(paths[i])) {
					return;
				}
			}
			String[] tmp = new String[paths.length + 1];
			System.arraycopy(paths, 0, tmp, 0, paths.length);
			tmp[paths.length] = s;
			field.set(null, tmp);
			paths = (String[]) field.get(null);
			StringBuilder sb = new StringBuilder(paths[0]);
			sb.append(System.getProperty("path.separator"));
			for (int i = 1; i < paths.length; i++) {
				sb.append(paths[i]);
				sb.append(System.getProperty("path.separator"));
			}
			System.setProperty("java.library.path", sb.toString());
		} catch (IllegalAccessException e) {
			// throw new IOException(
			// "Failed to get permissions to set library path");
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			// throw new IOException(
			// "Failed to get field handle to set library path");
			e.printStackTrace();
		}
	}
}
